package groovy.service

import groovy.model.User;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

class RegistServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp)
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		User user = User.fromRequest(req)
		user.save()
		user = user.pull()
		if(user) {
			req.getSession().setAttribute("user", user)
			resp.sendRedirect("index.jsp")
		} else {
			resp.sendRedirect("error.jsp")
		}
	}
}
